package com.hdjk.view.callback;

import com.hdjk.view.entity.ShopCarEntity;
import com.lst.projectlib.entity.Msg;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import okhttp3.Response;

/**
 * Created by sxy on 2017/11/2.
 */

public abstract class GetShopCarListCallBack extends MsgCallBack {
    @Override
    public Msg parseNetworkResponse(Response response, int i) throws Exception {
        Msg msg = super.parseNetworkResponse(response, i);
        JSONArray array = (JSONArray) msg.getData();
        if (array != null) {
            List<ShopCarEntity> list = new ArrayList<>();
            for (int j = 0; j < array.length(); j++) {
                JSONObject object = array.getJSONObject(j);
                if (object != null) {
                    ShopCarEntity entity = new ShopCarEntity();
                    if (!object.isNull("UserId")) {
                        entity.setUserId(object.getInt("UserId"));
                    }
                    if (!object.isNull("FundCode")) {
                        entity.setFundCode(object.getString("FundCode"));
                    }
                    if (!object.isNull("FundName")) {
                        entity.setFundName(object.getString("FundName"));
                    }
                    if (!object.isNull("UpdateTime")) {
                        entity.setUpdateTime(object.getString("UpdateTime"));
                    }
                    if (!object.isNull("Amount")) {
                        entity.setAmount(object.getString("Amount"));
                    }
                    if (!object.isNull("Id")) {
                        entity.setId(object.getString("Id"));
                    }
                    list.add(entity);
                }
            }
            msg.setData(list);
        }
        return msg;
    }
}
